--Gauntlet Event--

function Lookout_OnCombat(Unit, event)
    Unit:SetCombatCapable(1)
    Unit:SetNPCFlags(4)
    Unit:RegisterEvent("Waypoint1", 200, 1)
end

function Waypoint1(Unit, event)
    Unit:MoveTo(229.034607, 1468.416260, 25.916971, 4.691184)
       Unit:RegisterEvent("Waypoint2", 3950, 1)
end

function Waypoint2(Unit, event)
    Unit:MoveTo(228.258881, 1433.437134, 27.247080, 1.549781)
    Unit:RegisterEvent("Waypoint3", 4900, 1)
end

function Waypoint3(Unit, event)
    Unit:MoveTo(230.087448, 1367.468384, 48.110592, 0.308661)
    Unit:RegisterEvent("Waypoint4", 8900, 1)
    Unit:RegisterEvent("Wave1", 3000, 1)    
end

function Waypoint4(Unit, event)
    Unit:MoveTo(284.28818, 1378.752686, 49.321762, 3.446516)
    Unit:RegisterEvent("Waypoint5", 7900, 1)
    Unit:RegisterEvent("TempestDeathCheck", 5000, 0)
end

function Waypoint5(Unit, event)
    Unit:MoveTo(300.646362, 1384.543945, 57.763447, 5.975498)
    Unit:RegisterEvent("Waypoint6", 4000, 1)
end

function Waypoint6(Unit, event)
    Unit:MoveTo(369.476929, 1405.172852, 74.774590, 0.265464)
end

function TempestDeathCheck(Unit, event)
    if Tempest == 1 then
    Unit:RemoveEvents()
    Unit:Despawn(1, 1800000)
    else
    end
end

function Wave1(Unit, event)
        Unit:SpawnCreature(24225, 227.860931, 1486.371826, 25.916813, 4.761088, 1890, 0)
        Unit:SpawnCreature(24225, 230.254833, 1486.364624, 25.916813, 4.706110, 1890, 0)
        Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
        Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
        Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
        Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
        Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
        Unit:RegisterEvent("Wave2", 20000, 1)
end

function Wave2(Unit, event)
    Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
    Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
    Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
    Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)
    Unit:SpawnCreature(24159, 313.129028, 1386.663330, 57.163906, 3.434736, 1890, 0)           
    Unit:RegisterEvent("Wave1", 20000, 1)
end
    

function WarriorsOnSpawn(Unit, event)
    Unit:SpawnCreature(16474, 231.012863, 1469.179688, 25.917038, 1.392696, 4, 0)
end

function WarMoveTo(Unit, event)
    if go == 1 then
    Unit:RemoveEvents()
    Unit:RegisterEvent("WarMoveTo2", 1, 1)
    end
end

function WarMoveTo2(Unit, event)
    Unit:MoveTo(228.258881, 1433.437134, 27.247080, 1.549781)
    Unit:RegisterEvent("WarMoveTo3", 4900, 1)
end

function WarMoveTo3(Unit, event)
    Unit:MoveTo(230.087448, 1367.468384, 48.110592, 0.308661)
    end

function deathofally(Unit, event)
    go = 1
    Unit:Despawn(1, 0)
end

function EaglesOnSpawn(Unit, event)
    Unit:RegisterEvent("dummspawn", 2000, 1)
end

function dummyspawn(Unit, event)
    Unit:SpawnCreature(16474, 301.122009, 1385.599976, 57.853100, 3.23770, 4, 0)
    end

function EagleStart(Unit, event)
    if go == 1 then
    Unit:RemoveEvents()
    Unit:RegisterEvent("EagleWaypoint", 1, 1)
    end
end

function EagleWaypoint(Unit, event)
    Unit:MoveTo(300.646362, 1384.543945, 57.763447, 5.975498)
    Unit:RegisterEvent("EagleWaypoint2", 1000, 1)
end

function EagleWaypoint2(Unit, event)
    Unit:MoveTo(284.28818, 1378.752686, 49.321762, 3.446516)
    Unit:RegisterEvent("EagleWaypoint3", 2400, 1)
end

function EagleWaypoint3(Unit, event)
    Unit:MoveTo(230.087448, 1367.468384, 48.110592, 0.308661)
    Unit:RegisterEvent("EagleWaypoint4", 6900, 1)
end

function EagleWaypoint4(Unit, event)
    Unit:MoveTo(229.034607, 1468.416260, 25.916971, 4.691184)
end

function TempestDeath(Unit)
    Tempest = 1
    Unit:Despawn(1, 1800000)
end


RegisterUnitEvent(24175, 1, "Lookout_OnCombat")
RegisterUnitEvent(24225, 6, "WarriorsOnSpawn")
RegisterUnitEvent(24225, 2, "WarMoveTo")
RegisterUnitEvent(16474, 4, "deathofally")
RegisterUnitEvent(24159, 6, "EaglesOnSpawn")
RegisterUnitEvent(24159, 2, "EagleStart")
RegisterUnitEvent(24549, 4, "TempestDeath")

--AkilZonEncounter AI--

timer = math.random(5000,10000)
timer2 = math.random(10000, 20000)
timer3 = math.random(4000, 15000)
timer4 = math.random(9000, 15000)
timer5 = math.random(8000, 10000)
a = 1
b = 0

function Akilzon_OnCombat(Unit, event)
    aggro = math.random(1, 2)
    if aggro == 1 then
    Unit:SendChatMessage(14, 0, "I be da predator! you da prey...")
    Unit:PlaySoundToSet(12013)
    end
    if aggro == 2 then
    Unit:SendChatMessage(14, 0, "Your death will be quick, strangers. You shoulda have never come to this place...")
    Unit:PlaySoundToSet(12123)
    end
    Unit:RegisterEvent("Akilzon_ElectricalStorm", 60000, 0)
    Unit:RegisterEvent("Akilzon_GustOfWind", 30000, 0)
    Unit:RegisterEvent("Akilzon_StaticDisruption",timer, 0)
    Unit:RegisterEvent("Akilzon_CallLightning",timer2, 0)
    Unit:RegisterEvent("Akilzon_Enrage", 600000, 0)
end

function Akilzon_CallLightning(Unit)
    Unit:FullCastSpellOnTarget(43661, Unit:GetMainTank())
end

function Akilzon_GustOfWind(Unit)
    Unit:CastSpellOnTarget(38517, Unit:GetRandomPlayer(0))
end

function Akilzon_StaticDisruption(Unit)
    Unit:CastSpellOnTarget(44008, Unit:GetRandomPlayer(0))
end

function Akilzon_ElectricalStorm(Unit)
    Unit:RemoveEvents()
    Unit:StopMovement(8000)
    Unit:FullCastSpellOnTarget(43648, Unit:GetRandomPlayer(0))
    Unit:RegisterEvent("Akilzon_SummonEagles", 15000, 1)
    Unit:RegisterEvent("Akilzon_ElectricalStorm", 20000, 0)
    Unit:RegisterEvent("Akilzon_GustOfWind", 30000, 0)
    Unit:RegisterEvent("Akilzon_StaticDisruption",timer, 0)
    Unit:RegisterEvent("Akilzon_CallLightning",timer2, 0)
    Unit:RegisterEvent("Akilzon_Enrage", 600000, 0)
end

function Akilzon_Enrage(Unit)
    Unit:PlaySoundToSet(12016)
    Unit:CastSpell(34624)
end

function Akilzon_SummonEagles(Unit, event)
    Unit:SendChatMessage(14, 0, "Feed, me bruddahs!")
    Unit:PlaySoundToSet(12014)
    if b == 5 then
    end
    if b == 4 then
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    end
    if b == 3 then
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    end
    if b == 2 then
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 3, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 5, y + 2, z, o, 1890, 0)
    end
    if b == 1 then
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 3, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 5, y + 2, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x - 6, y - 5, z, o, 1890, 0)
    end
    if b == 0 then
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:SpawnCreature(24858, x, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 3, y, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x + 5, y + 2, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x - 6, y - 5, z, o, 1890, 0)
    Unit:SpawnCreature(24858, x - 10, y -10, z, o, 1890, 0)
    end
end

function Akilzon_OnKilledTarget(Unit, event)
    death = math.random(1, 2);
    if death == 1 then
    Unit:SendChatMessage(14, 0, "Ya got nothin'!")
    Unit:PlaySoundToSet(12017)
    end
    if death == 2 then
    Unit:SendChatMessage(14, 0, "Stop your cryin'!")
    Unit:PlaySoundToSet(12018)
end
end

function Akilzon_OnLeaveCombat(Unit, event)
    Unit:RemoveEvents()
end

function Akilzon_OnDied(Unit, event)
    Unit:SendChatMessage(14, 0, "You can't...kill...me spirit!")
    Unit:PlaySoundToSet(12019)
    Unit:RemoveEvents()
end

RegisterUnitEvent(23574, 1, "Akilzon_OnCombat")
RegisterUnitEvent(23574, 2, "Akilzon_OnKilledTarget")
RegisterUnitEvent(23574, 3, "Akilzon_OnLeaveCombat")
RegisterUnitEvent(23574, 4, "Akilzon_OnDied")

--Soaring EaglesAI--

function SoaringSwoop(Unit, event)
    Unit:GetRandomPlayer(0)
    b = a + 1
end

function SoaringDeath(Unit, event)
    b = a - 1
end

RegisterUnitEvent(24858, 6, "SoaringSwoop")
RegisterUnitEvent(24858, 4, "SoaringDeath")

--WindWalkerAI--

function WindWalker_OnCombat(Unit)
    Unit:RegisterEvent("WindWalkerFrostShock", 10000, 1)
    Unit:RegisterEvent("WindWalkerChainHeal", timer3, 1)
    Unit:RegisterEvent("WindWalkerLightningBolt", timer4, 1)
end

function WindWalkerFrostShock(Unit)
    Unit:FullCastSpellOnTarget(43524, Unit:GetClosestPlayer())
end

function WindWalkerChainHeal(Unit)
    
    Unit:FullCastSpell(43527)
end

function WindWalkerLightningBolt(Unit)
    
    Unit:FullCastSpellOnTarget(43526, Unit:GetMainTank())
end

function WindWalker_OnKilledTarget(Unit)
    Unit:RemoveEvents()
end

function WindWalker_OnLeaveCombat(Unit)
    Unit:RemoveEvents()
end

function WindWalker_OnDied(Unit)
    Unit:RemoveEvents()
end
    
RegisterUnitEvent(24179, 1, "WindWalker_OnCombat")
RegisterUnitEvent(24179, 2, "WindWalker_OnKilledTarget")
RegisterUnitEvent(24179, 3, "WindWalker_OnLeaveCombat")
RegisterUnitEvent(24179, 4, "WindWalker_OnDied")